var CustomerManaged = function () {

    return {

        //main function to initiate the module
        init: function () {
            
            if (!jQuery().dataTable) {
                return;
            }

            // begin first table
            $('#customer').dataTable({
                "aoColumns": [
                  { "bSortable": false },
                  { "bSortable": true },
                  { "bSortable": true },
                  { "bSortable": true },
                  { "bSortable": true },
                  { "bSortable": true },
                  { "bSortable": true },
                  { "bSortable": true },
                  { "bSortable": true },
                  { "bSortable": true },
                  { "bSortable": true }
                ],
                "aLengthMenu": [
                    [10, 15, 20, -1],
                    [10, 15, 20, "全部"] // change per page values here
                ],
                // set the initial value
                "iDisplayLength": 10,
                "sPaginationType": "bootstrap",
                "oLanguage": {
                    "sLengthMenu": "每页显示 _MENU_ 条",
                    "oPaginate": {
                        "sPrevious": "上一页",
                        "sNext": "下一页"
                    }
                },
                "aoColumnDefs": [{
                        'bSortable': false,
                        'aTargets': [0]
                    }
                ]
            });

            jQuery('#customer .group-checkable').change(function () {
                var set = jQuery(this).attr("data-set");
                var checked = jQuery(this).is(":checked");
                jQuery(set).each(function () {
                    if (checked) {
                        $(this).attr("checked", true);
                    } else {
                        $(this).attr("checked", false);
                    }
                    if($(this).parents('tr').attr("class").indexOf("active") > 0){
	               		 $(this).removeAttr("checked");
	               	 }else{
	               		 $(this).attr("checked",true);
	               	 }
                    $(this).parents('tr').toggleClass("active");
                });
                jQuery.uniform.update(set);

            });

            jQuery('#customer tbody tr .checkboxes').change(function(){
            	 if($(this).parents('tr').attr("class").indexOf("active") > 0){
            		 $(this).removeAttr("checked");
            	 }else{
            		 $(this).attr("checked",true);
            	 }
                 $(this).parents('tr').toggleClass("active");
            });

            jQuery('#customer_wrapper .dataTables_filter input').addClass("form-control input-medium"); // modify table search input
            jQuery('#customer_wrapper .dataTables_length select').addClass("form-control input-xsmall"); // modify table per page dropdown
            //jQuery('#sample_1_wrapper .dataTables_length select').select2(); // initialize select2 dropdown
        }

    };

}();